<?php 

/**
 * CodeRS - Atviras kodas Lietuvai
 * Copyright (C) 2007 CodeRS www.coders.lt info@coders.lt
 * MightMedia TVS
 * forumas.php - Forumo administravimas
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * 
 * 
 * Ši programa yra laisva. Jūs galite ją platinti ir/arba modifikuoti
 * remdamiesi Free Software Foundation paskelbtomis GNU Bendrosios
 * Viešosios licencijos sąlygomis: 2 licencijos versija, arba (savo
 * nuožiūra) bet kuria vėlesne versija.
 * 
 * Ši programa platinama su viltimi, kad ji bus naudinga, bet BE JOKIOS
 * GARANTIJOS; be jokios numanomos PERKAMUMO ar TINKAMUMO KONKRETIEMS
 * TIKSLAMS garantijos. Žiūrėkite GNU Bendrąją Viešąją licenciją norėdami
 * sužinoti smulkmenas.
 * 
 * Jūs turėjote kartu su šia programa gauti ir GNU Bendrosios Viešosios
 * licencijos kopija; jei ne - rašykite Free Software Foundation, Inc., 59
 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**/

if ($_SERVER['PHP_SELF'] == __FILE__) { header('location: ?'); exit(); }
if (!defined("LEVEL") || LEVEL < 30 || !defined("OK")) { header('location: index.php'); }
?>
		<h2>Forumo administravimas</h2>
		<fieldset>
		<legend>Funkcijos</legend>
		<table border="0">
			<tr>
				<td>
					<form name="f" action="<?=url('s,7;f,1')?>" method="post">
						<input type="submit" value="Forumo sukūrimas">
						<input type="hidden" name="action"  value="f" />
					</form>
					<form name="f" action="<?=url('s,7;f,2')?>" method="post">
						<input type="submit" value="Forumo redagavimas">
						<input type="hidden" name="action"  value="f" />
					</form>
					<form name="f" action="<?=url('s,7;f,3')?>" method="post">
						<input type="submit" value="Forumo temų sukūrimas">
						<input type="hidden" name="action"  value="f" />
					</form>
					<form name="f" action="<?=url('s,7;f,4')?>" method="post">
						<input type="submit" value="Forumo temų redagavimas">
						<input type="hidden" name="action"  value="f" />
					</form>
					<form name="f" action="<?=url('s,7;f,5')?>" method="post">
						<input type="submit" value="Moderatoriau nustatymas">
						<input type="hidden" name="action"  value="f" />
					</form>
					<form name="f" action="<?=url('s,7;f,7')?>" method="post">
						<input type="submit" value="Moderatoriaus panaikinimas">
						<input type="hidden" name="action"  value="f" />
					</form>
				</td>
				<td>
		</table>
		</fieldset>
		<?php
		// Paspaustas kazkoks mygtukas
		if (isset($_POST['action']) && $_POST['action'] == 'f_sukurimas') {
			$forumas = input($_POST['f_pav']);
			$result = $db->uzklausa("INSERT INTO `d_forumai` (`pav`) VALUES ('" . $forumas ."')");
			if ($result) {
				$f_info = "
						<fieldset>
						<legend>Informacija</legend>
							Forumas sėkmingai sukurtas
						</fieldset>
					";
			}
			else {
				$f_info = "
						<fieldset>
						<legend>Informacija</legend>
							Forumas nesukurtas. Klaida: <b>" . mysql_error() ."</b>
						</fieldset>
					";
			}
			echo $f_info;
			unset($f_info,$forumas,$result);
		}
		if (isset($_POST['action']) && $_POST['action'] == 'f_pav_keitimas') {
			$f_id = (int)$_POST['f_edit'];
			$f_pav_keitimas = input($_POST['f_pav_keitimas']);
			$result = $db->uzklausa("UPDATE `d_forumai` SET `pav`='" . $f_pav_keitimas ."' WHERE `id`='" . $f_id ."'");
			if ($result) {
				$f_info = "
						<fieldset>
						<legend>Informacija</legend>
							Forumo pavadinimas sėkmingai atnaujintas
						</fieldset>
					";
			}
			else {
				$f_info = "
						<fieldset>
						<legend>Informacija</legend>
							Forumo pavadinimas neatnaujintas. Klaida: <b>" . mysql_error() ."</b>
						</fieldset>
					";
			}
			echo $f_info;
			unset($f_info,$forumas,$result);
		}
		if (isset($_POST['action']) && $_POST['action'] == 'f_temos_sukurimas') {
			$f_id = (int)$_POST['f_forumas'];
			$f_tema= input($_POST['f_tema']);
			$f_aprasymas = input($_POST['f_aprasymas']);
			$result = $db->uzklausa("INSERT INTO `d_temos` (`fid`, `pav`, `aprasymas`) VALUES ('" . $f_id ."', '" . $f_tema ."', '" . $f_aprasymas ."')");
			if ($result) {
				$f_info = "
						<fieldset>
						<legend>Informacija</legend>
							Forumui priskirta tema sukurta
						</fieldset>
					";
			}
			else {
				$f_info = "
						<fieldset>
						<legend>Informacija</legend>
							Forumui priskirta tema nesukurta. Klaida: <b>" . mysql_error() ."</b>
						</fieldset>
					";
			}
			echo $f_info;
			unset($f_info,$forumas,$result);
		}
		if (isset($_POST['action']) && $_POST['action'] == 'f_temos_edit') {
			$sql = $db->uzklausa("SELECT * FROM `d_forumai` ORDER BY `id` ASC");
			$f_id = (int)$_POST['f_forumas'];
			$f_info = "
					<fieldset>
					<legend>Forumo temos redagavimas</legend>
					<form name=\"44\" action=\"?id,46;a,3\" method=\"post\">
					<table border=0 width=100%>
						<tr>
							<td width='15%'>Forumas:</td>
							<td>
								<select size=\"1\" name=\"f_forumas\">";
			while ($row = mysql_fetch_assoc($sql)) {
				$f_info .= "<option value='" . $row['id'] ."'";
				if ($row['id'] == $f_id) { $f_info .= " selected"; }
				$f_info .= ">" . $row['pav'] ."</option>";
			}
			unset($row,$sql);
			$sql = $db->uzklausa("SELECT * FROM `d_temos` WHERE `fid`='" . $f_id ."'");
			$f_info .= "
								</select>
							</td>
						</tr>
						<tr>
							<td>Tema:</td>
							<td>
								<select size=\"1\" name=\"f_tema\">";
			while ($row  = mysql_fetch_assoc($sql)) {
				$f_info .= "<option value='" . $row['id'] ."'>" . $row['pav'] ."</option>";
			}
			$f_info .= "
								</select>
							</td>
						</tr>
					</table>
					<input type=\"submit\" value=\"Redaguoti\">
					<input type=\"hidden\" name=\"action\"  value=\"f_temos_edit_se\" />
					</form>
					</fieldset>
				";
			echo $f_info;
			unset($f_info,$f_id,$sql,$row);
		}
		if (isset($_POST['action']) && $_POST['action'] == 'f_temos_edit_se') {
			$f_id = (int)$_POST['f_forumas'];
			$f_temos_id = (int)$_POST['f_tema'];
			$sql = mysql_fetch_assoc($db->uzklausa("SELECT pav FROM `d_forumai` WHERE `id`='" . $f_id ."'"));
			$f_forumas = $sql['pav'];
			unset($sql);
			$t_info = mysql_fetch_assoc($db->uzklausa("SELECT * FROM `d_temos` WHERE `fid`='" . $f_id ."'"));
			$f_text = "
					<fieldset>
					<legend>Forumo temos redagavimas</legend>
					<form name=\"44\" action=\"?id,46;a,3\" method=\"post\">
					<table>
						<tr>
							<td width='10%'>Forumas:</td>
							<td><b>" . $f_forumas ."</b><input type=\"hidden\" name=\"forumo_id\"  value='" . $f_id ."' /></td>
						<tr>
							<td>Tema:</td>
							<td><input name=\"temos_pav\" type=\"text\" value='" . $t_info['pav'] ."'><input type=\"hidden\" name=\"temos_id\"  value='" . $t_info['id'] ."' /></td>
						</tr>
							<td>Aprašymas:</td>
							<td><input name=\"temos_apr\" type=\"text\" value='" . $t_info['aprasymas'] ."'></td>
						</tr>
					</table>
					<input type=\"submit\" value=\"Atnaujinti\">
					<input type=\"hidden\" name=\"action\" value=\"t_update\" />
					</form>
					</fieldset>
				";
			echo $f_text;
			unset($f_text,$t_info,$f_id,$f_temod_id,$sql,$f_forumas);
		}
		if (isset($_POST['action']) && $_POST['action'] == 't_update') {
			$f_forumas = (int)$_POST['forumo_id'];
			$f_tema = (int)$_POST['temos_id'];
			$edit_tema = input($_POST['temos_pav']);
			$edit_aprasymas = input($_POST['temos_apr']);
			$result = $db->uzklausa("UPDATE `d_temos` SET `pav`='" . $edit_tema ."', `aprasymas`='" . $edit_aprasymas ."' WHERE `fid`='" . $f_forumas ."' AND `id`='" . $f_tema ."'");
			if ($result) {
				$f_info = "
						<fieldset>
						<legend>Informacija</legend>
							Pasirinkto forumo tema sėkmingai atnaujinta
						</fieldset>
					";
			}
			else {
				$f_info = "
						<fieldset>
						<legend>Informacija</legend>
							Pasirinkto forumo tema neatnaujinta. Klaida: <b>" . mysql_error() ."</b>
						</fieldset>
					";
			}
			echo $f_info;
		}
		// #############################################################
		// Parodome pasirinktos funkcijos laukelius
		// ##############################################################
		if (isset($url['s']) && (int)$url['id'] == 46 && (int)$url['s'] == 7 && isset($url['f'])) {
			if ((int)$url['f'] == 1) {
				echo "
					<br>
					<br>
						<fieldset>
						<legend>Forumo sukūrimas</legend>
						<form name=\"1\" action=\"?id,46;a,3\" method=\"post\">
							Forumo pavadinimas:&nbsp;&nbsp;<input name=\"f_pav\" type=\"text\" value=\"\">
							<input type=\"submit\" value=\"Sukurti\">
							<input type=\"hidden\" name=\"action\"  value=\"f_sukurimas\" />
						</form>
						</fieldset>
					";
			}
			if ((int)$url['f'] == 2) {
				$sql = $db->uzklausa("SELECT * FROM `d_forumai` ORDER BY `id` ASC");
				$f_text = "
					<br>
					<br>
					<fieldset>
					<legend>Forumo pavadinimo redagavimas</legend>
					<form name=\"2\" action=\"?id,46;a,3\" method=\"post\">
					<table border=0 width=100%>
						<tr>
							<td width='10%'>Forumas:</td>
							<td><select size=\"1\" name=\"f_edit\">";
				while($row = mysql_fetch_assoc($sql)) {
					$f_text .= "<option value=" . $row['id'] .">" . $row['pav'] ."</option>\n";
				}
				$f_text .= "</select>
  							</td>
  						</tr>
  						<tr>
  							<td>Keisti į:</td>
  							<td><input name=\"f_pav_keitimas\" type=\"text\" value=\"\"></td>
  						</tr>
  					</table>
  					<input type=\"submit\" value=\"Keisti\">
					<input type=\"hidden\" name=\"action\"  value=\"f_pav_keitimas\" />
					</fieldset>
					";
				echo $f_text;
				unset($f_text,$sql,$row);
			}
			if ((int)$url['f'] == 3) {
				$sql = $db->uzklausa("SELECT * FROM `d_forumai` ORDER BY `id` ASC");
				$f_text = "
					<br>
					<br>
					<fieldset>
					<legend>Forumo temų sukūrimas</legend>
					<form name=\"3\" action=\"?id,46;a,3\" method=\"post\">
					<table border=0 width=100%>
						<tr>
							<td width='10%'>Forumas:</td>
							<td><select size=\"1\" name=\"f_forumas\">";
				while($row = mysql_fetch_assoc($sql)) {
					$f_text .= "<option value=" . $row['id'] .">" . $row['pav'] ."</option>\n";
				}
				$f_text .= "</select>
  							</td>
  						</tr>
  						<tr>
  							<td>Temos pavadinimas:</td>
  							<td><input name=\"f_tema\" type=\"text\" value=\"\"></td>
  						</tr>
  						<tr>
  							<td>Aprašymas:</td>
  							<td><input name=\"f_aprasymas\" type=\"text\" value=\"\">
  						</tr>
  					</table>
  					<input type=\"submit\" value=\"Įrašyti\">
					<input type=\"hidden\" name=\"action\"  value=\"f_temos_sukurimas\" />
					</fieldset>
					";
				echo $f_text;
				unset($f_text,$sql,$row);
			}
			if ((int)$url['f'] == 4) {
				$sql = $db->uzklausa("SELECT * FROM `d_forumai` ORDER BY `id` ASC");
				$f_text = "
					<br>
					<br>
					<fieldset>
					<legend>Forumo temų sukūrimas</legend>
					<form name=\"\" action=\"?id,46;a,3\" method=\"post\">
					<table border=0 width=100%>
						<tr>
							<td width='10%'>Forumas:</td>
							<td><select size=\"1\" name=\"f_forumas\">";
				while($row = mysql_fetch_assoc($sql)) {
					$f_text .= "<option value='" . $row['id'] ."'>" . $row['pav'] ."</option>\n";
				}
				$f_text .= "
  								</select>
  							</td>
  						</tr>
  					</table>
  					<input type=\"submit\" value=\"Pasirinkti\">
					<input type=\"hidden\" name=\"action\"  value=\"f_temos_edit\" />
					</form>
					</fieldset>
					";
				echo $f_text;
				unset($f_text,$sql,$row);
			}
		}
		?>
	</div>
	</div>